package slaythespire;

import com.megacrit.cardcrawl.cards.AbstractCard;
import org.jboss.byteman.rule.Rule;
import org.jboss.byteman.rule.helper.Helper;

import java.util.ArrayList;

public class StsHelper extends Helper {
    protected StsHelper(Rule rule) {
        super(rule);
    }

    private static Thread cardThread = new CardsUIThread();

    public static ArrayList<AbstractCard> cardList = new ArrayList<>();

    public void runUI() {
        if (!cardThread.isAlive()) {
            cardThread.start();
        }
    }

    public void returnCards(ArrayList<AbstractCard> old) {
        super.traceln("cardlist size = " + cardList.size());
        for (AbstractCard newCard : cardList) {
            boolean isExist = false;
            for (AbstractCard oldCard : old) {
                if (oldCard.cardID.equals(newCard.cardID)) {
                    isExist = true;
                    break;
                }
            }
            if (!isExist) {
                AbstractCard removed = old.remove(0);
                if (removed.upgraded && newCard.canUpgrade()) {
                    newCard.upgrade();
                }
                old.add(newCard);
            }
        }
    }
}
